cmake_minimum_required(VERSION 3.8)
project(planning_bringup)

# Default to C++17
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 17)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# Find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_components REQUIRED)
find_package(std_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(visualization_msgs REQUIRED)
find_package(tf2 REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(tf2_geometry_msgs REQUIRED)

# Find planning dependencies
find_package(eudm_planner REQUIRED)
find_package(behavior_planner REQUIRED)
find_package(ssc_planner REQUIRED)
find_package(semantic_map_manager REQUIRED)
find_package(common REQUIRED)
find_package(Boost REQUIRED COMPONENTS system)
find_package(OpenCV REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(Protobuf REQUIRED)
find_package(OpenMP REQUIRED)

# Set third party include directories for nanoflann
set(THIRD_PARTY_INCLUDE_DIRS /home/yz/Code/EPSILON/map/semantic_map_manager/thirdparty)

# Include directories
include_directories(
  ${rclcpp_INCLUDE_DIRS}
  ${eudm_planner_INCLUDE_DIRS}
  ${behavior_planner_INCLUDE_DIRS}
  ${ssc_planner_INCLUDE_DIRS}
  ${semantic_map_manager_INCLUDE_DIRS}
  ${common_INCLUDE_DIRS}
  ${EIGEN3_INCLUDE_DIR}
  ${OpenCV_INCLUDE_DIRS}
  ${PROTOBUF_INCLUDE_DIRS}
  /home/yz/Code/EPSILON/build/eudm_planner  # For generated protobuf headers
  /home/yz/Code/EPSILON/build/ssc_planner   # For generated protobuf headers
  ${THIRD_PARTY_INCLUDE_DIRS}  # For nanoflann
)

# Create executables
add_executable(test_ssc_with_eudm
  src/test_ssc_with_eudm.cc
)

add_executable(test_ssc_with_mpdm
  src/test_ssc_with_mpdm.cc
)

# Add ROS2 dependencies to executables
ament_target_dependencies(test_ssc_with_eudm
  rclcpp
  rclcpp_components
  std_msgs
  geometry_msgs
  sensor_msgs
  visualization_msgs
  tf2
  tf2_ros
  tf2_geometry_msgs
  eudm_planner
  ssc_planner
  semantic_map_manager
  common
)

target_link_libraries(test_ssc_with_eudm
  Boost::system
  ${OpenCV_LIBRARIES}
  ${PROTOBUF_LIBRARIES}
  OpenMP::OpenMP_CXX
)

ament_target_dependencies(test_ssc_with_mpdm
  rclcpp
  rclcpp_components
  std_msgs
  geometry_msgs
  sensor_msgs
  visualization_msgs
  tf2
  tf2_ros
  tf2_geometry_msgs
  behavior_planner
  ssc_planner
  semantic_map_manager
  common
)

target_link_libraries(test_ssc_with_mpdm
  Boost::system
  ${OpenCV_LIBRARIES}
  ${PROTOBUF_LIBRARIES}
  OpenMP::OpenMP_CXX
)

# Install executables
install(TARGETS
  test_ssc_with_eudm
  test_ssc_with_mpdm
  DESTINATION lib/${PROJECT_NAME}
)

# Install launch files
install(DIRECTORY launch/
  DESTINATION share/${PROJECT_NAME}/launch
  FILES_MATCHING PATTERN "*.py"
)

# Install config files if any
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/config)
  install(DIRECTORY config/
    DESTINATION share/${PROJECT_NAME}/config
  )
endif()

# Testing
if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()